function processFile(blob, fileName, toolId) { var data = new FormData(); data.append('file', blob); data.append('fileName', fileName); data.append('toolId', toolId); $('.extra-input input').each(function (i, obj) { data.append($(this).attr('name'), $(this).val()); }); $('#file-drop-zone').addClass('collapsedDropZone'); $('#waiting').show(); $.ajax({ url: "/Home/UploadFile", type: 'POST', data: data, contentType: false, processData: false, success: function (data) { $('#waiting').hide(); if (data.result == 2) { $('#social').fadeIn(5000); var dl = document.createElement('a'); // output file dl.setAttribute('href', data.outputFileName); dl.setAttribute('download', data.outputFileDescription); $(dl).text(data.outputFileDescription); $('#output-files').append($(dl)); fireEvent(dl, 'click'); } else if (data.result == -3) { alert('This file type is not supported or the file header is corrupted. Please use an image program to convert your file to one of the following: ' + data.supported_file_types + '. Contact us at info@convert.town if this problem continues.') } else if (data.result == -6) { alert('This image file could not be opened. Perhaps it is corrupt? Please view the image to ensure that it is valid. Contact us at info@convert.town if this problem continues.') } else if (data.result == -7) { alert('Please enter a valid DPI number between 1 and 2000. Contact us at info@convert.town if this problem continues.') } else { alert("An error occurred. Send the file to info@convert.town and we will get it working for you as soon as possible.") } }, error: function () { $('#waiting').hide(); alert("an error occured - contact us if the problem continues"); } }); } function convert(input) { alert('Error. Contact us at info@convert.town if this keeps happening'); } function replaceAll(find, replace, str) { return str.replace(new RegExp(find, 'g'), replace); } function beautify(str) { var result = ''; var length = str.length; var i = 0; var braceCountLeft = 0; var braceCountRight = 0; var withinQuotes = false; while (i < length) { var c = str[i]; if (c == '"' && (i == 0 || c[i - 1] != '\\')) { // non-escaped quotes withinQuotes = !withinQuotes; } if (!withinQuotes && (c == '}' || c == '{' || c == ',')) { console.log('Start####' + result); // look back and remove carriage returns and whitespace that are already there var resultIndex = result.length - 1; while (resultIndex >= 0 && (result[resultIndex] == ' ' || result[resultIndex] == '\r' || result[resultIndex] == '\n' || result[resultIndex] == '\t')) { resultIndex = resultIndex - 1; result = result.substr(0, resultIndex + 1); console.log('char ' + result[resultIndex] + '-----' + result + 'zzz ' + result.length + ' ' + resultIndex); } if (c == '{') { braceCountLeft++; result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } else if (c == '}') { braceCountRight++; // precede with carriage return result += '\r' + GetTabs(braceCountLeft - braceCountRight) + c; } else if (c == ',') { result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } var nextChar = ''; // advance through whitespace and remove carriage returns that are already there while (i < length && (str[i + 1] == ' ' || str[i + 1] == '\r' || str[i + 1] == '\n' || str[i + 1] == '\t')) { i++; } } else { result += str[i]; } i++; } return result; } function GetTabs(count) { var result = ''; for (var i = 0; i < count; i++) { result += ' '; } return result; }